package com.ruoyi.fun.dto;

import com.fasterxml.jackson.annotation.JsonProperty;

/**
 * 购物车更新DTO
 * 用于处理前端传递的字符串类型cartId，避免大数值精度丢失
 */
public class CartUpdateDto {
    
    @JsonProperty("cartId")
    private String cartId;
    
    @JsonProperty("quantity")
    private Integer quantity;
    
    @JsonProperty("checked")
    private Boolean checked;
    
    @JsonProperty("userId")
    private Long userId;
    
    @JsonProperty("orgId")
    private Long orgId;
    
    public String getCartId() {
        return cartId;
    }
    
    public void setCartId(String cartId) {
        this.cartId = cartId;
    }
    
    public Integer getQuantity() {
        return quantity;
    }
    
    public void setQuantity(Integer quantity) {
        this.quantity = quantity;
    }
    
    public Boolean getChecked() {
        return checked;
    }
    
    public void setChecked(Boolean checked) {
        this.checked = checked;
    }
    
    public Long getUserId() {
        return userId;
    }
    
    public void setUserId(Long userId) {
        this.userId = userId;
    }
    
    public Long getOrgId() {
        return orgId;
    }
    
    public void setOrgId(Long orgId) {
        this.orgId = orgId;
    }
    
    /**
     * 转换为Long类型的cartId
     */
    public Long getCartIdAsLong() {
        if (cartId == null || cartId.trim().isEmpty()) {
            return null;
        }
        try {
            return Long.parseLong(cartId);
        } catch (NumberFormatException e) {
            throw new IllegalArgumentException("Invalid cartId format: " + cartId);
        }
    }
}